package com.ruoyi.merchant.mapper;

import com.ruoyi.common.core.cg.pojo.Group;
import com.ruoyi.common.core.cg.pojo.Template;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface TemplateMapper {
    /**
     * 根据负责人ID获取模板列表
     *
     * @param leaderId 负责人ID
     * @return 模板列表
     */
//    @Select("SELECT t.* FROM t_template t " +
//            "JOIN t_leader_template lt ON t.id = lt.template_id " +
//            "WHERE lt.leader_id = #{leaderId}")
    List<Template> selectTemplatesByLeaderId(Integer leaderId);


    /**
     * 添加新的模板
     *
     * @param template 要添加的模板对象
     * @return 包含操作结果的ResponseEntity对象
     */
    @Insert("INSERT INTO t_template (product_name, product_spec, retail_price, group_price, min_group_size, max_group_size, selected_group_size, purchase_limit, total_groups, total_stock, start_time, end_time, pickup_time, product_desc, status, create_time, update_time) " +
            "VALUES (#{productName}, #{productSpec}, #{retailPrice}, #{groupPrice}, #{minGroupSize}, #{maxGroupSize}, #{selectedGroupSize}, #{purchaseLimit}, #{totalGroups}, #{totalStock}, #{startTime}, #{endTime}, #{pickupTime}, #{productDesc}, #{status}, #{createTime}, #{updateTime})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    int insertTemplate(Template template);

    /**
     * 删除模版
     *
     * @param id
     * @return
     */
    @Delete("DELETE FROM t_template WHERE id = #{id}")
    int deleteTemplateById(Integer id);

    /**
     * 修改模版
     * @param template
     * @return
     */
    @Update("UPDATE t_template SET product_name = #{productName}, product_spec = #{productSpec}, " +
            "retail_price = #{retailPrice}, group_price = #{groupPrice}, min_group_size = #{minGroupSize}, " +
            "max_group_size = #{maxGroupSize}, selected_group_size = #{selectedGroupSize}, " +
            "purchase_limit = #{purchaseLimit}, total_groups = #{totalGroups}, total_stock = #{totalStock}, " +
            "start_time = #{startTime}, end_time = #{endTime}, pickup_time = #{pickupTime}, " +
            "product_desc = #{productDesc}, status = #{status}, update_time = #{updateTime} " +
            "WHERE id = #{id}")
    int updateTemplate(Template template);


    @Insert("insert into `t_template`(people,total_group,\n" +
            "pick_up_time,price,group_price,\n" +
            "status,create_time,limit_buy,\n" +
            "end_time,surface_plot,first_img,\n" +
            "second_img,remark,invitation_code,\n" +
            "name,max_group,group_status)\n" +
            "values(#{people},#{totalGroup},\n" +
            "#{pickUpTime},#{price},#{groupPrice},\n" +
            "#{status},#{createTime},#{limitBuy},\n" +
            "#{endTime},#{surfacePlot},#{firstImg},\n" +
            "#{secondImg},#{remark},#{invitationCode},\n" +
            "#{name},#{maxGroup},#{groupStatus}\n" +
            ")")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    int saveTemplate(Template template);


    //根据id查询商品信息
    List<Template> queryTemplate(int lid);

    //删除模板表
    @Delete("DELETE FROM t_leader_template WHERE template_id = #{id} AND leader_id = #{lid}")
    int deleteLeaderGroup(@Param("id") Integer id,@Param("lid") Integer lid);
}
